Skip to content

fix(albums): index freshly-added album when dir has a stale photomap_index#247

Merged
lstein merged 2 commits into
masterfrom
lstein/fix/auto-index-stale
May 21, 2026
Merged

fix(albums): index freshly-added album when dir has a stale photomap_index#247
lstein merged 2 commits into
masterfrom
lstein/fix/auto-index-stale

Conversation

@lstein
Copy link
Copy Markdown
Owner

@lstein lstein commented May 20, 2026

Bug

After creating a new album whose chosen image directory already contained a stale `photomap_index/embeddings.npz` from a prior session (e.g. recreating an album over the same folder), creating the album appeared to succeed but the indexing UI got stuck at "Index updated …" in orange at 0% completion that never advanced. The new album silently inherited the old index — searches and the UMAP were against the prior session's image set, not the current one.

Root cause

Two compounding bugs:

  1. `startAutoIndexing` never actually started indexing. It's the only entry point that runs after `addAlbum`, and it just called `showProgressUI` on a 500 ms timer with a comment "Don't start indexing again - it's already running." The only path that does start indexing for a new album was the `albumIndexError` event fired from `getIndexMetadata` when the index returns 404. With a stale `embeddings.npz` already on disk, the metadata fetch succeeds, no error event fires, and `/update_index_async/` is never POSTed.

  2. CSS `!important` orange wins over inline green. `updateAlbumCardIndexStatus` set `status.style.color = "green"` inline but never reset `className`. The CSS for `.index-status.indexing` carries `color: #ff9800 !important` (so the in-progress state wins over the inline updates that `updateProgressStatus` makes per status transition). When `showProgressUI` runs first and sets `className = "index-status indexing"`, the inline green that `updateAlbumCardIndexStatus` sets afterwards has no visual effect.

Fix

  • `startAutoIndexing` now scrolls the album card's indexing section into view, then calls `startIndexing(albumKey, albumCard)` directly. `startIndexing` is already idempotent — its backend-progress probe attaches to an in-flight run instead of double-POSTing — so the no-prior-index path (where the `albumIndexError` listener also calls `startIndexing`) still triggers exactly one backend request.
  • `updateAlbumCardIndexStatus` resets `className = "index-status"` before applying the inline color, so a stale state class can't override.

Test plan

  • `npm run lint` + `npm run format:check` — clean
  • `npm test` — 288 passed
  • `pytest tests/backend` — 257 passed (no backend changes, ran for safety)
  • Manual repro:
    1. Create an album pointing at a directory, let it index.
    2. Delete the album from PhotoMap (leave the `photomap_index/` directory on disk).
    3. Re-create an album with the same image directory.
    4. Before fix: orange "Index updated …" at 0% forever.
    5. After fix: indexing kicks off, progress UI advances scanning → indexing → mapping → green "Indexing completed successfully".

🤖 Generated with Claude Code

lstein and others added 2 commits May 20, 2026 17:26
…tomap_index

If the directory chosen for a new album already contained a
``photomap_index/embeddings.npz`` from a prior session (e.g. the user
recreated an album over the same folder), creating the album appeared
to succeed but the indexing UI got stuck at "Index updated …" in orange
with 0% completion that never advanced. The new album silently
inherited the old index.

Two compounding bugs:

* ``startAutoIndexing`` — the only entry point that runs after
  ``addAlbum`` — called ``showProgressUI`` and nothing else. It assumed
  indexing was already running, which was only true when
  ``getIndexMetadata`` failed and fired the ``albumIndexError`` event.
  With a stale ``embeddings.npz`` in place, the metadata fetch
  succeeds, no error event fires, and indexing was never started.
  Now ``startAutoIndexing`` scrolls into view and calls ``startIndexing``
  directly. ``startIndexing`` is already idempotent — its backend
  progress probe attaches to any in-flight run instead of double-POSTing
  ``/update_index_async/``.

* ``updateAlbumCardIndexStatus`` set ``status.style.color = "green"``
  inline but didn't reset ``className``. CSS for
  ``.index-status.indexing`` carries ``!important`` (so the in-progress
  state's color wins over inline updates from ``updateProgressStatus``),
  which meant a stale ``.indexing`` class left behind by
  ``showProgressUI`` overrode the inline green. Resetting className to
  the bare ``index-status`` fixes the color and makes future state
  classes win cleanly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lstein lstein merged commit 7d8ea59 into master May 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant